﻿using System;

using HsTec.Mobile.Green.Util;
using HsTec.Mobile.Green.BLL;
using Baimasoft.Manage.SqlServerDAL;

public partial class ReportAnalysis_ForecastBusinessImport : System.Web.UI.Page
{
    ReportAnalysisBLL bll = new ReportAnalysisBLL();
    Param MyP = new Param();
    protected void Page_Load(object sender, EventArgs e)
    {
        if ((string)Session["Baimasoft_Pers_ID"] == null)
        {
            Response.Redirect("../Logon.aspx");
        }
        if (!IsPostBack)
        {
            txtYearsDataBind();
        }
    }
    protected void btn_Statistics_ServerClick(object sender, EventArgs e)
    {
        //验证
        if (String.IsNullOrEmpty(txtYears.SelectedValue.Trim()))
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请选择导入年份！');</script>");
            return;
        }
        //1.验证上传文件类型
        string UpfileExt = System.IO.Path.GetExtension(FU_Statistics.FileName);
        if (UpfileExt != ".xls")
        {
            Text_Confirm_Upstate.Text = "入库的文件名类型不符要求！（必须是EXCEL文件）";
            return;
        }
        //2.验证数据是否已经上传
        //2.1 上传文件
        switch (Util.Upload_File(FU_Statistics, FU_Statistics.FileName, "09"))
        {
            case 1:
                Text_Confirm_Upstate.Text = "上传文件成功！";
                break;
            case 0:
                Text_Confirm_Upstate.Text = "上传文件失败！";
                return;
        }
        //2.2 导入到DataSet中
        ExcelHelper ehelper = new ExcelHelper();
        ehelper.insertTableName = "tb_ForecastBusiness";
        ehelper.excelPath = "09\\" + FU_Statistics.FileName;
        Text_Confirm_Upstate.Text = ehelper.importPlanningData(txtYears.SelectedValue.Trim(), Session["Baimasoft_Pers_ID"].ToString());
        Util.Delete_File(FU_Statistics.FileName, "09");
    }
    private void txtYearsDataBind()
    {
        txtYears.DataTextField = "Name";
        txtYears.DataValueField = "Name";
        txtYears.DataSource = MyP.GetCodeByParentCode("2");
        txtYears.DataBind();
        txtYears.Items.Insert(0, "请选择...");
        txtYears.Items[0].Value = "";
    }
}
